package com.yungu.swift.admin.route.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.utils.ExcelUtil;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminParam;
import com.yungu.swift.system.finance.model.param.AdminAccountFlowPageParam;
import com.yungu.swift.system.sys.model.vo.SysAccountPlatformVo;
import com.yungu.swift.system.sys.model.vo.SysPlatformAccountFlowVo;
import com.yungu.swift.system.sys.service.SysAccountPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/12/23
 */
@RestController
@RequestMapping("/admin/v1/finance/balance/platform")
@Api(value = "【财务管理】", tags = "平台账户管理")
public class PlatformBalanceAdmin {

    @Reference
    private SysAccountPlatformService sysAccountPlatformService;

    @RequestMapping(value = "/statistics", method = RequestMethod.POST)
    @ApiOperation(value = "平台账户统计", httpMethod = "POST")
    public ResponseData<SysAccountPlatformVo> statistics(@RequestBody AdminParam adminParam) {
        return sysAccountPlatformService.statistics(adminParam);
    }


    @RequestMapping(value = "/flowQueryPage", method = RequestMethod.POST)
    @ApiOperation(value = "平台账户流水分页查询", httpMethod = "POST")
    public ResponseData<PageVo<SysPlatformAccountFlowVo>> flowQueryPage(@RequestBody AdminAccountFlowPageParam flowPageParam) {
        return sysAccountPlatformService.flowQueryPage(flowPageParam);
    }

    @RequestMapping(value = "/flowExport", method = RequestMethod.POST)
    @ApiOperation(value = "平台账户流水导出", httpMethod = "POST")
    public void flowExport(@RequestBody AdminAccountFlowPageParam flowPageParam, HttpServletResponse response) {
        ResponseData<List<SysPlatformAccountFlowVo>> flowExport = sysAccountPlatformService.flowExport(flowPageParam);
        if (flowExport.isSuccess() && CollectionUtils.isNotEmpty(flowExport.getData())) {
            List<SysPlatformAccountFlowVo> flowExportData = flowExport.getData();
            Map<Object, Object>[] dictionaryMapArray = new Map[6];
            ExcelUtil.export(response, "平台账户流水", flowExportData, 6,
                    new String[]{"时间", "流水号", "订单号", "交易类型", "交易类目", "金额（元）"},
                    new String[]{"createOn", "financeNumber", "orderNo", "transactionType", "courseDescription", "amount"},
                    dictionaryMapArray);
        }
    }
}
